package com.dorm.cj.design.module;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;

import java.io.IOException;
import java.math.BigDecimal;

/*
BigDecimal类型序列化时转为String
 */
public class BigDecimalSerializer extends StdScalarSerializer<BigDecimal> {

    protected BigDecimalSerializer() {
        super(BigDecimal.class);
    }

    @Override
    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String bigDecimalToStr = bigDecimal.toString();
        jsonGenerator.writeString(bigDecimalToStr);
    }
}
